<?php if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class Asset_employees extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->CI =& get_instance();
		$c_model = $this->session->userdata('formodel');
		$this->load->model('wus');
		$this->load->model($this->session->userdata('formodel'));
		$this->load->library('variable');
		$this->load->library('PHPexcel');

	}

	public function index(){
	  $this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));
	  $this->load->view($this->session->userdata('formain'),[
	  		'emp_pos'	=>	$this->asset_employees_model->getLookUp('EMP_POS'),
	  		'emp_dep'	=>	$this->asset_employees_model->getLookUp('EMP_DEP'),
	  		'sex'		=>	$this->asset_employees_model->getLookUp('SEX')
	  	]);
	  $this->load->view('layouts/footer');
	 }

	 public function add_form(){
		$this->load->view($this->session->userdata('foradd'),[
	  		'emp_pos'	=>	$this->asset_employees_model->getLookUp('EMP_POS'),
	  		'emp_dep'	=>	$this->asset_employees_model->getLookUp('EMP_DEP'),
	  		'sex'		=>	$this->asset_employees_model->getLookUp('SEX')
	  	]);
	}

	public function edit_form($id){
		$this->load->view($this->session->userdata('foredit'),[
			'edit_data'	=>	$this->asset_employees_model->getData($id),
			'emp_pos'	=>	$this->asset_employees_model->getLookUp('EMP_POS'),
	  		'emp_dep'	=>	$this->asset_employees_model->getLookUp('EMP_DEP'),
	  		'sex'		=>	$this->asset_employees_model->getLookUp('SEX')
		]);
	}

	public function view_form($id){
		$this->load->view($this->session->userdata('forview'),[
			'edit_data'	=>	$this->asset_employees_model->getData($id),
			'emp_pos'	=>	$this->asset_employees_model->getLookUp('EMP_POS'),
	  		'emp_dep'	=>	$this->asset_employees_model->getLookUp('EMP_DEP'),
	  		'sex'		=>	$this->asset_employees_model->getLookUp('SEX')
		]);
	}

	public function insert()
	{
		$data = [
			':1'		=> $this->input->post('empPrefix'),
			':2'		=> $this->input->post('empFName'),
			':3'		=> $this->input->post('empMInit'),
			':4'		=> $this->input->post('empLName'),
			':5'		=> $this->input->post('sex'),
			':6'		=> $this->input->post('empDep'),
			':7'		=> $this->input->post('empPos'),
			':8'		=> $this->session->userdata('user_id')
		];

		$query = $this->asset_employees_model->insert_data($data);
		echo json_encode($query);
	}

	public function update()
	{
		$data = [
			':1'	=> $this->input->post('employeeID'),
			':2'	=> $this->input->post('empDep_e'),
			':3'	=> $this->input->post('empPos_e'),
			':p_user_id'		=> $this->session->userdata('user_id')
		];

		$query = $this->asset_employees_model->update_data($data);
		echo json_encode($query);
	}

	public function search(){
		echo json_encode($this->asset_employees_model->search($this->input->post('fname'),$this->input->post('lname'),$this->input->post('sex'),$this->input->post('dep'),$this->input->post('pos')));
	}
}
